import { post, get, deleteR, patch } from "@/http/request";
import type { LoginResult, LoginData, UserInfo, IRoleList } from "./type";
import type { ApiResponse } from "@/api";

export const userLogin = async (data: LoginData) => {
	return post<any>({}, "/auth/login", data);
};

export const getUserInfo = async () => {
	return get<any>({}, "/user/info");
};

//新增用户
export const addUser = async (data: UserInfo) => {
	return post<any>({}, "/user", data);
};
// 修改用户
export const updateUser = async (data: any) => {
	return patch<any>({}, `/user/${data.id}`, data);
};

// 查询用户列表
export const getList = async (params: any) => {
	return get<any>({}, "/user", params);
};

// 删除用户
export const delUser = async (id: number) => {
	return deleteR<any>({}, `/user/${id}`);
};

// 根据用户id获取角色列表
// export const getRoleList = async (id: number) => {
// 	return get<ApiResponse<IRoleList>>({}, `/user/${id}/role`);
// };

// 分配角色
export const reqAssignRole = async (id: number, data: { roleIds: Array<number> }) => {
	return patch<any>({}, `/user/${id}/assignRole`, data);
};
